package org.mysfit.ctp4j.test;

import java.util.Collections;

import org.mysfit.ctp4j.core.service.BaseService;
import org.mysfit.ctp4j.core.service.impl.AbstractBaseServiceImpl;
import org.mysfit.ctp4j.infra.entity.BaseEntity;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

/**
 * 
 * @author long.gf
 *
 */
public class DemoGenerator {
	public static void main(String[] args) {
		FastAutoGenerator
				.create("jdbc:mysql://10.10.234.60:3306/ctp4j?useUnicode=true&characterEncoding=utf-8&useSSL=false", "ctp4j_rw", "ctp4j_rw")
				.globalConfig(builder -> {
					builder.author("long.gf") // 设置作者
							.enableSwagger() // 开启 swagger 模式
							.fileOverride() // 覆盖已生成文件
							.outputDir("E:\\tmp\\ctp4j"); // 指定输出目录
				})
				.packageConfig(builder -> {
					builder.parent("org.mysfit.ctp4j") // 设置父包名
							.moduleName("") // 设置父包模块名
							.entity("infra.entity")
							.service("core.service")
							.serviceImpl("core.service.impl")
							.mapper("infra.mapper")
							.controller("api.controller.v1")
							.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\tmp\\ctp4j")); // 设置mapperXml生成路径
				})
				.strategyConfig(builder -> {
					builder.addInclude("demo") // 设置需要生成的表名
							.addTablePrefix("t_", "c_"); // 设置过滤表前缀
					builder.entityBuilder()
							.superClass(BaseEntity.class)
							.addSuperEntityColumns("id", "created_time", "updated_time")
							.build();
					builder.serviceBuilder() // Service
							.superServiceClass(BaseService.class)
							.superServiceImplClass(AbstractBaseServiceImpl.class)
							.formatServiceFileName("%sService")
							.formatServiceImplFileName("%sServiceImpl")
							.build();
				})
				.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
				.execute();
	}
}